package string_test;

import java.lang.reflect.Field;

public class StringChange {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
//        String str = "hello ";
//        str += "wolrd ";
//        str += "!!!";
//        System.out.println(str);

        String str = "hello";
        System.out.println(str);
        Class<String> cls = String.class;
        // 获取这个属性
        Field field = cls.getDeclaredField("value");
        // 破坏封装，破坏private
        field.setAccessible(true);
        // 在String类的外部通过反射拿到value数组
        char[] value = (char[]) field.get(str);
        value[0] = 'H';
        System.out.println(str);
    }
}
